import { Controller } from "../../../../mvc/core/Controller";
import { ICopyController } from "./ICopyController";
import { TCopy } from "../../../../../Message/Db/Tables/TCopy";
import { LaterUtil } from "../../../../common/LaterUtil";
import { EDifficultyOption } from "../../../../../Message/Public/EDifficultyOption";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { CopyUtil } from "../CopyUtil";
//class CopyControllerBase
    
    export  class CopyControllerBase extends Controller implements ICopyController
    {
        constructor()
        {
            super();
            return;
        }

        public get copy(): TCopy
        {
            return this._copy;
        }

        public enterCopy(arg1: TCopy): void
        {
            this._copy = arg1;
            this.addListener();
            LaterUtil.stopCallLater(this.releaseKey);
            if (this._copy && this._copy.difficultyNum == EDifficultyOption._EDifficultySerious) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.EnterKingCopy));
            }
            return;
        }

        public leaveCopy(): void
        {
            this.removeListener();
            LaterUtil.addCallLater(this.releaseKey, this.dispose, 120);
            if (this._copy && this._copy.difficultyNum == EDifficultyOption._EDifficultySerious) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.LeaveKingCopy));
            }
            this._copy = null;
            return;
        }

        protected get releaseKey(): string
        {
            if (this._releaseKey == "") 
            {
                this._releaseKey = CopyUtil.getReleaseKey();
            }
            return this._releaseKey;
        }

        protected addListener(): void
        {
            return;
        }

        protected removeListener(): void
        {
            return;
        }

        public updateCopyProcess(): void
        {
            return;
        }

        public stageResize(): void
        {
            return;
        }

        public dispose(): void
        {
            return;
        }

        /* internal */ /* var */_copy: TCopy;

        /* internal */ /* var */_releaseKey: string="";
    }
